package com.linwen.excise.leetcode;

/**
 * @ClassName _1232缀点成线
 * @Description TODO
 * @Author zero
 * @DATE 2024/4/5 7:21 PM
 * @Version 1.0
 */
public class _1232缀点成线 {
    public static void main(String[] args) {
        // [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]
        int[][] coordinates = new int[][]{{1,2},{2,3},{3,4},{4,5},{5,6},{6,7}};
        System.out.println(checkStraightLine(coordinates));
    }

    public static boolean checkStraightLine(int[][] coordinates) {
        int deltaX = coordinates[0][0], deltaY = coordinates[0][1];
        int n = coordinates.length;
        for (int i = 0; i < n; i++) {
            coordinates[i][0] -= deltaX;
            coordinates[i][1] -= deltaY;
        }
        int A = coordinates[1][1], B = -coordinates[1][0];
        for (int i = 2; i < n; i++) {
            int x = coordinates[i][0], y = coordinates[i][1];
            if (A * x + B * y != 0) {
                return false;
            }
        }
        return true;
    }
}
